package com.cpp.server.controller;

import com.cpp.common.constant.ModuleConstant;
import com.cpp.common.result.Result;
import com.cpp.pojo.dto.exam.AnswerDTO;
import com.cpp.pojo.dto.exam.ExamQuestionConfirmDTO;
import com.cpp.pojo.dto.question.QuestionGenerateDTO;
import com.cpp.pojo.vo.question.AnswerRightVO;
import com.cpp.pojo.vo.question.QuestionCreateConfirmVO;
import com.cpp.pojo.vo.question.QuestionExamVO;
import com.cpp.server.aspect.annotation.MyLog;
import com.cpp.server.service.QuestionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/question")
@MyLog(module = ModuleConstant.OTHERS)
public class QuestionController {
    private final QuestionService questionService;

//    @PostMapping("/create")
//    public String createQuestion(String courseId, String examId, String questionType, String questionContent, String answer, String analysis) {
//        return questionService.createQuestion(courseId, examId, questionType, questionContent, answer, analysis);
//    }
//自动生成题目返回          后端校验某道题的答案返回是否正确，或者答案正确性
    @MyLog(module = ModuleConstant.PRE_EXAM)
    @PutMapping("/confirm")
    public Result confirmQuestion(@RequestBody ExamQuestionConfirmDTO examQuestionConfirmDTO) {
        questionService.updateQuestion(examQuestionConfirmDTO);
        return Result.success();
    }
    //自动生成题目返回
    @MyLog(module = ModuleConstant.PRACTICE)
    @PostMapping("generate")
    public Result generateQuestion(@RequestBody QuestionGenerateDTO questionGenerateDTO) {
        List<QuestionExamVO> questionExams = questionService.generateQuestion(questionGenerateDTO);
        return Result.success(questionExams);
    }
    //后端校验某道题的答案返回是否正确，和答案正确性
    @MyLog(module = ModuleConstant.PRACTICE)
    @PostMapping("/check")
    public Result checkAnswer(@RequestBody AnswerDTO answer) {
        AnswerRightVO answerRightVO = questionService.checkAnswer(answer);
        return Result.success(answerRightVO);
    }
    //返回所有题目
    @MyLog(module = ModuleConstant.PRACTICE)
    @GetMapping("/listPractice")
    public Result listQuestion() {
        List<QuestionExamVO> questionExams = questionService.listPractice();
        return Result.success(questionExams);
    }
}
